package com.ely.coupon.common.swagger.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@AutoConfiguration
@EnableConfigurationProperties(SwaggerConfigurationProperties.class)
@Slf4j
public class SwaggerConfiguration {
    private SwaggerConfigurationProperties configurationProperties;

    public SwaggerConfiguration(SwaggerConfigurationProperties configurationProperties) {
        this.configurationProperties = configurationProperties;
    }

    @Bean
    public Docket docket(ApiInfo apiInfo) {
        log.info("11111");
        return new Docket(DocumentationType.OAS_30)
                //
                .apiInfo(apiInfo)
                //
                .groupName(configurationProperties.getGroupName())
                //
                .enable(configurationProperties.isEnabled()).select()
                //
                .apis(RequestHandlerSelectors.basePackage(configurationProperties.getBasePackage()))
                //
                .paths(PathSelectors.any()).build();
    }

    @Bean
    public ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //
                .title(configurationProperties.getTitle())
                //
                .description(configurationProperties.getDescription())
                //
                .contact(new Contact(configurationProperties.getName(), configurationProperties.getUrl(), configurationProperties.getEmail()))
                //
                .build();
    }
}
